package com.boarsoft.boar.soagov.face.action;

import java.util.ArrayList;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.boarsoft.boar.common.Constants;
import com.boarsoft.boar.soagov.entity.FaceImpl;
import com.boarsoft.boar.soagov.face.FaceImplBiz;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.Util;
import com.boarsoft.common.action.PageAction;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.common.util.JsonUtil;

@SuppressWarnings("serial")
@Component
@Scope("prototype")
@ParentPackage("default-package")
@Namespace(value = "/face/impl")
public class FaceImplAction extends PageAction {
	@Autowired
	private FaceImplBiz faceImplBiz;

	private String id;
	private String key;
	private String faceId;
	private String impl;// 查询用
	private String version;

	/**
	 * 查询所有接口
	 */
	@Action("list")
	@Authorized(code = "face.impl.list")
	public void list() {
		PagedResult<FaceImpl> pr = null;
		if (Util.strIsEmpty(faceId)) {
			pr = new PagedResult<FaceImpl>(0, new ArrayList<FaceImpl>(), pageNo, pageSize);
		} else {
			pr = faceImplBiz.list(faceId, key, orderBy, pageNo, pageSize);
		}
		writeReply(true, JsonUtil.from(pr));
	}

	@Action("save")
	@Authorized(code = "face.impl.save")
	public void save() {
		FaceImpl fa = new FaceImpl();
		fa.setId(id);
		if (!this.isValid("faceId")) {
			writeReply(Constants.ERROR_INVALID, "Msg.common.param");
			return;
		} else {
			fa.setFaceId(faceId);
		}
		if (!this.isValid("impl")) {
			writeReply(Constants.ERROR_INVALID, "Msg.common.param");
			return;
		} else {
			fa.setImpl(impl);
		}
		if (!this.isValid("version")) {
			writeReply(Constants.ERROR_INVALID, "Msg.common.param");
			return;
		} else {
			fa.setVer(version);
		}
		faceImplBiz.save(fa);
		writeReply();
	}

	@Action("delete")
	@Authorized(code = "face.impl.delete")
	public void delete() {
		if (!this.isValid("id")) {
			writeReply(Constants.ERROR_INVALID, "Msg.common.param");
			return;
		}
		faceImplBiz.delete(id);
		writeReply();
	}

	@Action("get")
	@Authorized(code = "face.impl.get")
	public void get() {
		if (!this.isValid("id")) {
			writeReply(Constants.ERROR_INVALID, "Msg.common.param");
			return;
		}
		FaceImpl a = faceImplBiz.get(id);
		writeReply(true, JsonUtil.from(a));
	}

	public FaceImplBiz getFaceImplBiz() {
		return faceImplBiz;
	}

	public void setFaceImplBiz(FaceImplBiz faceImplBiz) {
		this.faceImplBiz = faceImplBiz;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getFaceId() {
		return faceId;
	}

	public void setFaceId(String faceId) {
		this.faceId = faceId;
	}

	public String getImpl() {
		return impl;
	}

	public void setImpl(String impl) {
		this.impl = impl;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}
}